package cn.tedu.store.config.util;

import cn.tedu.store.entity.CalledInfo;
import cn.tedu.store.entity.Tenant;
import cn.tedu.store.entity.Variable;
import com.alibaba.fastjson.JSONObject;

import java.text.SimpleDateFormat;
import java.util.*;

public class SendPhoneUtil {
    public static void main(String[] args) {
        ArrayList<CalledInfo> calledInfos = new ArrayList<>();
        CalledInfo calledInfo = new CalledInfo();
        calledInfo.setPhone("16607228157");
        calledInfo.setRemark("1");
        calledInfo.setContacts("范学宇");
        ArrayList<Variable> variables = new ArrayList<>();
        Variable variable = new Variable();
        variable.setKey("general");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    variable.setValue("时间："+simpleDateFormat1.format(new Date())+"枝江市人民医院欢迎你！");
    variables.add(variable);
    calledInfo.setVariable(variables);
    calledInfos.add(calledInfo);
    sendPhone(calledInfos);

    }

    public static void sendPhone(List<CalledInfo> calledInfos){
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //获取token
        com.alibaba.fastjson.JSONObject body = new com.alibaba.fastjson.JSONObject();
        body.put("username","13477857785");
        body.put("apiKey","6a$@m?*j261@l!f");
        body.put("transactionId","10086202211141249");
        Map s =   (Map)com.alibaba.fastjson.JSONObject.parseObject(HttpUtil
                .doPost(HttpUtil.url + HttpUtil.token, body)).get("bean");
        //请求头
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", (String) s.get("token"));
        String format = simpleDateFormat.format(date);
        String code = String.valueOf((int) ((Math.random() * 9 + 1) * Math.pow(10, 5)));
        //添加任务
        Tenant tenant = new Tenant();
        tenant.setTransactionId(1085+format+code);
        tenant.setTenantId("2023040310553681671");
        tenant.setProcessId(2023041815093205645L);
        tenant.setProcessName("通用");
        tenant.setTaskName("通用"+simpleDateFormat1.format(new Date()));
        tenant.setConcurrentNum(1);
        tenant.setOutCallNums("07174516097");
        tenant.setIsAllday(1);
        tenant.setForever(0);
        tenant.setRecallNum(2);
        tenant.setRecallTime(1);
        tenant.setPlanStime("2023-01-11");
        tenant.setPlanEtime("2025-01-11");
        tenant.setStartTime1("08:00:00");
        tenant.setEndTime1("12:00:00");
        tenant.setStartTime2("14:30:00");
        tenant.setEndTime2("17:30:00");
        tenant.setCalledInfo(calledInfos);
        System.out.println(tenant);
        String s1 = HttpUtil.doPostJson(HttpUtil.url + HttpUtil.Task, headers, JSONObject.toJSONString(tenant));
        System.out.println(s1);


    }


}
